package com.github.andy0106.kersstcli.client;

import com.github.andy0106.kersstjtl.api.ApiBuffer;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

import java.io.IOException;

public class KersstApplication extends Application {
    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(KersstApplication.class.getResource("gui-view.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 1000, 700);
        stage.setTitle("KersstClient-0.1");
        stage.setScene(scene);
        KersstController controller = fxmlLoader.getController();
        controller.init();
        stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent windowEvent) {
                ApiBuffer.save();
            }
        });
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}